package lxy;

public class LockTest {
    public static void main(String[] args) {

        Ticket ticket = new Ticket();

        Thread t1 = new Thread(ticket,"第一个窗口");
        Thread t2 = new Thread(ticket,"第二个窗口");
        Thread t3 = new Thread(ticket,"第三个窗口");
        t1.start();
        t2.start();
        t3.start();

    }
}

class Ticket implements Runnable{
    private int count = 100;
    @Override
    public void run() {
        while (count > 0){
            synchronized (this) {
                if (count > 0){
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖了第" + (100 - count + 1) + "张票");
                    count--;
                }
            }
        }
    }

}